package com.ruoyi.web.controller.cms.fileInfo;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.fileInfo.domain.CmsFileInfo;
import com.ruoyi.cms.fileInfo.service.ICmsFileInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件信息管理Controller
 *
 * @author linyang
 * @date 2025-07-22
 */
@RestController("AdminCmsFileInfoController")
@RequestMapping("/admin/cms/fileInfo")
public class CmsFileInfoController extends BaseController {


    @Resource
    private ICmsFileInfoService cmsFileInfoService;

    /**
     * 查询文件信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('cms:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsFileInfo cmsFileInfo) {
        startPage();
        List<CmsFileInfo> list = cmsFileInfoService.selectCmsFileInfoList(cmsFileInfo);
        return getDataTable(list);
    }

    /**
     * 导出文件信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('cms:info:export')")
    //@Log(title = "文件信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsFileInfo cmsFileInfo) {
        List<CmsFileInfo> list = cmsFileInfoService.selectCmsFileInfoList(cmsFileInfo);
        ExcelUtil<CmsFileInfo> util = new ExcelUtil<CmsFileInfo>(CmsFileInfo.class);
        util.exportExcel(response, list, "文件信息管理数据");
    }

    /**
     * 获取文件信息管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('cms:info:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return success(cmsFileInfoService.selectCmsFileInfoByFileId(fileId));
    }

    /**
     * 新增文件信息管理
     */
    //@PreAuthorize("@ss.hasPermi('cms:info:add')")
    //@Log(title = "文件信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsFileInfo cmsFileInfo) {
        return toAjax(cmsFileInfoService.insertCmsFileInfo(cmsFileInfo));
    }

    /**
     * 修改文件信息管理
     */
    //@PreAuthorize("@ss.hasPermi('cms:info:edit')")
    //@Log(title = "文件信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsFileInfo cmsFileInfo) {
        return toAjax(cmsFileInfoService.updateCmsFileInfo(cmsFileInfo));
    }

    /**
     * 删除文件信息管理
     */
    //@PreAuthorize("@ss.hasPermi('cms:info:remove')")
    //@Log(title = "文件信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(cmsFileInfoService.deleteCmsFileInfoByFileIds(fileIds));
    }
}
